import sys

sys.path.append('/usr/local/lib/python3.6/site-packages')
sys.path.append('/root/anaconda3/lib/python3.6/site-packages')
sys.path.append('../')

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from pymongo import MongoClient
from selenium import webdriver

import platform
import pprint
import codecs
import time
import json
import re
import os
import sys

if sys.stdout.encoding != 'UTF-8':
    sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
if sys.stderr.encoding != 'UTF-8':
    sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')


def new_driver(headless = False):
    if 'Darwin' in platform.platform():
        options = webdriver.ChromeOptions()

        if headless:
            options.add_argument('--headless')
            options.add_argument('--disable-gpu')
            options.add_argument('--disable-images')

        desired_capabilities = options.to_capabilities()

        chrome_driver_path = '/Users/xuchaosheng/Workspace/cv_match/binary/chromedriver'
        driver = webdriver.Chrome(chrome_driver_path, desired_capabilities = desired_capabilities)
    else:
        from selenium.webdriver import FirefoxOptions

        opts = FirefoxOptions()
        opts.add_argument('--headless')
        driver = webdriver.Firefox(firefox_options = opts)

    return driver


driver = new_driver()
driver.get('https://passport.zhaopin.com/org/login')

time.sleep(1)

# ele = driver.find_element_by_class_name('login-wx')
# actions = ActionChains(driver)
# actions.move_to_element_with_offset(ele, 50, 10)
# actions.click()
# actions.perform()

# driver.find_element_by_class_name('login-wx').click()

# driver.execute_script("""
#     document.querySelector('#loginName').value = 'sousuozhanghao2';
#     document.querySelector('#password').value = 'zhaopin123'
# """)

# driver.find_element_by_id('loginName').click()
# time.sleep(1)
# driver.find_element_by_id('loginName').send_keys('sousuozhanghao2')
# time.sleep(3)
# driver.find_element_by_id('password').click()
# time.sleep(1)
# driver.find_element_by_id('password').send_keys('zhaopin123')

# time.sleep(1)
# driver.find_element_by_id('loginbutton').click()

time.sleep(1000)
